package com.cy.store.service.impl;

import com.cy.store.entity.District;
import com.cy.store.mapper.DistrictMapper;
import com.cy.store.service.IDistrictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: AngJie
 * @create: 2022-02-07 23:28
 **/
@Service
public class DistrictServiceImpl implements IDistrictService {

    @Autowired
    DistrictMapper districtMapper;


    @Override
    public List<District> getByParent(String parent) {
        List<District> list = districtMapper.findByParent(parent);
        /*
        * 在网络数据进行传输时，为了尽量避免无效数据的传递，可以将无效数据设置null
        * 可以节省流量，另一方面提升了效率
        * */
        // 也可以在数据库的映射文件的sql查询中不查询id与parent
        for (District d :
                list) {
            d.setId(null);
            d.setParent(null);
        }
        return list;
    }

    @Override
    public String getNameByCode(String code) {
        String name = districtMapper.findNameByCode(code);
        return name;
    }

}
